package Petgoods;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

/*
卖家控制器，可以上架商品数量（对商品表product进行修改，增加对应商品数量）
 */
public class Sellcontrols {
    public void Shelf() {
        Sellermeau seller = new Sellermeau();
        seller.meau();

        JdbcUtil util = new JdbcUtil();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入想要增加商品名字：");
        String name = sc.nextLine();
        System.out.println("增加的数量");
        int num = sc.nextInt();

        String sql = "update product set number=number+? where name=?";
        try {
            Connection conn = util.getConn();
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1, num);
            ps.setString(2, name);
            int rows = ps.executeUpdate();
            if (rows > 0) {
                System.out.println("上架成功");
            }
            util.closeResource(null, conn, ps);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}